package com.workManager.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.workManager.mapper.TdFunctionMapper;
import com.workManager.pojo.TbProject;
import com.workManager.pojo.TdFunction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by Thinkpad on 2017/3/3 0003.
 */
@Service
public class FunctionServiceImpl implements  FunctionService {
    @Autowired
    private TdFunctionMapper functionMapper;
    public int add(TdFunction function) {
        return functionMapper.insert(function);
    }

    public int delete(String functionId) {
        return functionMapper.deleteByPrimaryKey(Integer.parseInt(functionId));
    }

    public int deleteByList(List<String> functionIds) {
        int i = 0;
        for (String functionId:functionIds) {
            i+=delete(functionId);
        }
        return i;
    }

    public PageInfo<TdFunction> query(Map map) {
        int pageno = !map.containsKey("pagenum")||map.get("pagenum")==null?1:Integer.parseInt(map.get("pagenum").toString());
        int pagesize = !map.containsKey("pagesize")||map.get("pagesize")==null?10:Integer.parseInt(map.get("pagesize").toString());
        PageHelper.startPage(pageno,pagesize);

        List<TdFunction> functionList = functionMapper.query(map);
        PageInfo<TdFunction> functionPageInfo = new PageInfo<TdFunction>(functionList);
        return  functionPageInfo;

    }

    public int update(TdFunction function) {
        return functionMapper.updateByPrimaryKey(function);
    }
}
